﻿namespace GoFun.Lib

module Positionen =

    let rowOf (position : Position) = fst position
    let colOf (position : Position) = snd position

    let validPos (dim : int) (pos : Position) =
        match pos with
        | (z, s) when z < 0 || s < 0 
            -> false
        | (z, s) when z >= dim || s >= dim 
            -> false
        | _ -> true


    let surrounding (dim :  int) (position : Position) =
        let zeile, spalte = position
        let valid p = validPos dim p
        let oben = (zeile-1), spalte
        let unten = (zeile+1), spalte
        let links = zeile, (spalte-1)
        let rechts = zeile, (spalte+1)
        let result = 
            [ links; oben; unten; rechts ]
            |> List.filter valid
        result